﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--自适应界面,如果出现,在某些设备出现界面偏小的话,检查一下有没有加入这句 -->
    <meta http-equiv="Content-type" name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="../../../js/jqmobile/jquery.mobile-1.4.5.min.css" />
    <link href="../../../js/layer_mobile/need/layer.css" rel="stylesheet" />
    <link href="../../../css/mobiscroll.css" rel="stylesheet" />
    <link href="../../../css/mobiscroll_date.css" rel="stylesheet" />
    <!--<script src="../js/jquery.js"></script>-->
    <script src="../../../js/jquery.min2.1.4.js"></script>
    <script src="../../../js/jqmobile/jquery.mobile-1.4.5.min.js"></script>
    <script src="../../../js/cordova-1.5.0.js"></script>
    <script src="../../../js/layer_mobile/layer.js"></script>
    <script src="../../../js/jshelp.js"></script>
    <script src="../../../js/jqmobile/mobiscroll_date.js" charset="gb2312"></script>
    <script src="../../../js/jqmobile/mobiscroll.js"></script>
    <script src="../../../js/layer/layer.js"></script>
    <script>
        $(function () {
            $('#sel_date').hide();
            $('#bdyy').hide();
            layer.config({
                extend: '../../../js/layer/extend/layer.ext.js'
            });
            var currYear = (new Date()).getFullYear();
            var opt = {};
            opt.date = { preset: 'date' };
            opt.datetime = { preset: 'datetime' };
            opt.time = { preset: 'time' };
            opt.default = {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示模式 modal|inline|bubble|top|bottom 默认modal
                //display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                dateFormat: 'yyyy-mm-dd',
                lang: 'zh',
                //showNow: true,
                nowText: "今天",
                startYear: currYear, //开始年份
                endYear: currYear  //结束年份
            };
            $("#starttime").mobiscroll($.extend(opt['date'], opt['default']));
            $("#endtime").mobiscroll($.extend(opt['date'], opt['default']));
        });
        //接受传参
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(decodeURI(r[2])); return null; //返回参数值
        }
        var userid = getUrlParam('userid');
        var username = getUrlParam('username');
        var billdate = getUrlParam('billdate');

        var date = new Date();
        var getdate = getNowFormatDate();//当前日期
        var getdate_last = date.getFullYear() + '-01-01'; //本年第一天
        jQuery(document).ready(function () {
            //if (userid == "" || userid == null) {
            //    window.location.href = "../Default.aspx";
            //}
            //else {
            $("#txt_dpname").val(username);
            $("#starttime").val(getdate);
            $("#endtime").val(getdate);
            $.ajax({
                type: "post",
                async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
                url: "ashx/list.ashx?type=selectlist_yyzt",    //请求发送到TestServlet处
                data: {},
                dataType: "json",        //返回数据形式为json
                success: function (result) {
                    var str = '';
                    $('#select_yyzt').html('');
                    //请求成功时执行该函数内容，result即为服务器返回的json对象
                    if (result.item.length > 0) {
                        str += ' <select data-native-menu="false" name="yyzt" id="sel_yyzt">';
                        //加载营业状态
                        for (var i = 0; i < result.item.length; i++) {
                            str += ' <option value="' + result.item[i].id + '">' + result.item[i].name + '</option>';
                        }
                        str += '</tr>';
                        $('#select_yyzt').append(str);
                    }
                    else {
                        //layer.msg("无数据");
                    }
                }
            })
            //}
        });

        function getdata() {
            var sel_yyzt = $('#sel_yyzt').val();
            if (sel_yyzt == "1") {
                $('#sel_date').hide();
                $('#bdyy').hide();
            }
            else if (sel_yyzt == "2") {
                $('#sel_date').show();
                $('#bdyy').hide();
            } else if (sel_yyzt == "3") {
                $('#sel_date').show();
                $('#bdyy').show();
            }
        }
        var clickCount = 1;
        function save() {
            debugger

            var sel_yyzt = $('#sel_yyzt').val();
            var starttime = $('#starttime').val(); 
            var endtime = $('#endtime').val(); 
            var txt_bdyy = $('#txt_bdyy').val(); 
            if (sel_yyzt == "3") {
                if (txt_bdyy == "" || txt_bdyy == undefined || txt_bdyy == null) {
                    layer.msg("其他原因闭店必须填写闭店原因", { time: 2000 })
                    return false;
                }
            }
            //防止多次点击
            if (clickCount >= 2) {
                return false;
            }
            else {
                $.ajax({
                    type: "post",
                    async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
                    url: "ashx/list.ashx?type=save",    //请求发送到TestServlet处
                    data: {
                        sel_yyzt: sel_yyzt, starttime: starttime, endtime: endtime,
                        txt_bdyy: txt_bdyy, userid: userid, username: username, billdate: billdate
                    },
                    dataType: "json",        //返回数据形式为json
                    success: function (result) {
                        debugger
                        if (result.flag == "True") {
                            clickCount++;
                            //提示
                            layer.open({
                                content: "上报成功!"
                                , skin: 'msg'
                                , time: 5 //5秒后自动关闭
                                , end: function (index) {
                                    location.reload();
                                }
                            });
                        } else {
                            //询问框
                            //提示
                            layer.open({
                                content: result.remsg
                                , skin: 'msg'
                                , time: 5 //2秒后自动关闭
                            });
                        }
                    }
                })
            }
        }
    </script>
</head>
<body>
    <div data-role="page" id="pageone">
        <div data-role="header" data-position="fixed">
            <h1>营业情况上报</h1>
        </div>
        <div data-role="main" class="ui-content">
            <div>
                <label style="color:red;font-size:20px;font-weight:bold;" for="fname">上报成功，谢谢您的配合!</label>
            </div>
        </div>
    </div>
</body>
</html>
